<?php
	class school_week extends spModel{
		var $pk = "id"; // 每个留言唯一的标志，可以称为主键
		var $table = "school_weeks"; // 数据表的名称
		
		var $validator = array(
			"rules" => array(
				'name' => array(
					'required' => true,
					'minlength' => 1,
					'maxlength' => 20
				),
		
			),
			"messages" => array(
				'name' => array(
					'required' => '教学周名称不能为空',
					'minlength' => '教学周名称最少1个字符',
					'maxlength' => '教学周名称请在2~20位字符之间'
				),
			)
		);
		public function checkEndtime($starttime, $endtime){
			if($endtime <= $starttime){
				return false;
			}else{
				return true;
			}
		}	
		public function checkNextStarttime($starttime,$id=0){
			$weeksList = $this ->findAll(array('isdel'=>0,'id <>' =>$id ),'endtime desc');
			if($lastEndTime && (strtotime($lastEndTime['endtime']) >= $starttime)){
				return false;
			}else{
				return true;
			}
		}

		/*
		 * 根据时间获得所在教学周
		 * */
		public function getNowWeek($datestr){
			if(!$datestr)
				throw new Exception("时间不能为空");
			$condition = array(
				"starttime <=" => $datestr,
				"endtime >=" => $datestr,
				"status" => "1",
				"isdel" => 0
			);
			return $this->find($condition);
		}
	}
?>